package com.AX.controller;

import com.AX.entity.PathRequest;
import com.AX.entity.PathResponse;
import com.AX.exception.NoPathException;
import com.AX.service.PathService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/navigation")
@RequiredArgsConstructor
public class NavigationController {

    @Resource
    private final PathService pathService;

    @PostMapping("/path")
    public ResponseEntity<?> getNavigationPath(@RequestBody PathRequest request) {
        System.out.println("路径生成中");
        System.out.println(request.getTargetSpaceId());
        System.out.println(request.getCurrentPosition());
        System.out.println(request.getParkingLotId());
        try {
            PathResponse response = pathService.calculatePath(request);

            System.out.println("路径成功返回");
            System.out.println(response);
            return ResponseEntity.ok(response);
        } catch (NoPathException e) {
            System.out.println("路径生成失败");
            return ResponseEntity.status(HttpStatus.BAD_REQUEST)
                    .body(Map.of("error", "No available path found"));
        }
    }
}
